import axios from 'axios'

import { idParser, nameParser, gradeClassParser } from '../utils/parser'
import checker from '../utils/checker'

import HeaderModel from '../model/header.model'
import CampusInfo from '../model/campusInfo.model'

const getUserId = async (url: string, headers: HeaderModel): Promise<CampusInfo> => {
  const { data } = await axios.get(url, { headers: { ...headers } })
  const id = idParser(data)!
  const name = nameParser(data)!
  const gradeClass = gradeClassParser(data)!
  checker(id && name && gradeClass, '', '无法获取用户信息')
  return { id, name, gradeClass }
}

export default getUserId
